/** @noSelfInFile **/

import {LocModel} from "../../base/LocModel";
import {ITexttagAdapter, textAdapter} from "../../adapter/adapterInterface/model2/ITexttagAdapter";
import {GlobalModel} from "../model1/GlobalModel";
import {HandleModel} from "../model1/HandleModel";

export class TexttagModel implements HandleModel {
    public handle: any;
    id: string;
    nikeName: string;

    textAdapter: ITexttagAdapter;

    constructor(name: string, size: number, loc: LocModel) {
        this.nikeName = name;

        this.textAdapter = textAdapter.adapter;
        let textTagHandle = this.textAdapter.createHandle(name);
        if (textTagHandle) {
            this.bindHandle(textTagHandle);
            this.setText(name, size)
            if (loc.z) {
                this.setPos(loc, loc.z)
            }
        }
    }

    getHandleId(): string {
        return this.id;
    }

    public setColor(red: number, green: number, blue: number, alpha: number) {
        this.textAdapter.setColor(this.handle, red, green, blue, alpha);
    }
    public setPos(loc: LocModel, heightOffset: number) {
        this.textAdapter.setPos(this.handle, loc, heightOffset);
    }

    public setText(s: string, height: number, adjustHeight = false) {
        this.textAdapter.setText(this.handle, s, height, adjustHeight);
    }

    destroy() {
        this.textAdapter.destroy(this.handle);
        this.handle = undefined;
    }

    bindHandle(handle: any) {
        this.handle = handle;
        this.id = GlobalModel.getHandleId(this.handle);
    }

    equal(handle: TexttagModel): boolean {
        return this.textAdapter.equal(this.handle, handle.handle);
    }

    isValid(): boolean {
        return this.textAdapter.isValid(this.handle);
    }
}
